package com.entity;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PageBean<T> {
    private int pageNo = 1;//当前页数,默认为1
    private int pageSize = 5;//每页行数
    private int rowCount;//共有行数
    private int totalPage;//共有页数
    private int startIndex=0;//limit起始索引
    private String[] factor;//查询条件数组
    private List<T> data;//查询的数据
    private List<Map> data1;

    public List<Map> getData1() {
        return data1;
    }

    public void setData1(List<Map> data1) {
        this.data1 = data1;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
        setStartIndex();
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        setTotalPage();
        setStartIndex();
    }

    public int getRowCount() {
        return rowCount;
    }


    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
        setTotalPage();
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage() {
        this.totalPage = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;
        setStartIndex();
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex() {
        int startIndex =(pageNo-1)*pageSize;
        if(startIndex>=0){
            this.startIndex=startIndex;
        }else{
            this.startIndex=0;
        }
    }

    public String[] getFactor() {
        return factor;
    }

    public void setFactor(String[] factor) {
        this.factor = factor;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", rowCount=" + rowCount +
                ", totalPage=" + totalPage +
                ", startIndex=" + startIndex +
                ", condition=" + Arrays.toString(factor) +
                ", data=" + data +
                '}';
    }
}

